package com.tour.tour.utils;

import com.tour.tour.dto.UserDTO;
import com.tour.tour.exception.UserStatusException;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import javax.servlet.http.HttpServletRequest;

import static com.tour.tour.utils.constant.RedisConstant.LOGIN_USER_KEY;

/**
 * @author 76004
 * @apiNote
 * @date 2023/4/27 20:07
 */

public class UserInfoUtil {
    @Autowired
    public static StringRedisTemplate stringRedisTemplate;

    public static String getUid(HttpServletRequest httpServletRequest) throws UserStatusException {
        String tokenKey = httpServletRequest.getHeader("Authorization");
        System.out.println(tokenKey);
        String uid = TokenUtil.getClaimsFromToken(tokenKey).getSubject();
        if(uid == null){
            throw new UserStatusException("用户未登录");
        }
        return uid;
    }
}
